<template>
  <div class="xtx-goods-page">
    <div class="container" v-if="goods.categories">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="`/category/${goods.categories[1].id}`">{{
          goods.categories[1].name
        }}</XtxBreadItem>
        <XtxBreadItem :to="`/category/sub/${goods.categories[0].id}`">{{
          goods.categories[0].name
        }}</XtxBreadItem>
        <XtxBreadItem>{{ goods.name }}</XtxBreadItem>
      </XtxBread>
      <!-- 【商品信息】 -->
      <div class="goods-info">
        <!-- !【左侧】 -->
        <div class="media">
          <!-- 图片预览 -->
          <XtxImageView :imageList="goods.mainPictures" />
          <!-- 数量 -->
          <GoodsSale :goods="goods" />
        </div>
        <!-- !【右侧】 -->
        <div class="spec">
          <!-- 商品信息 -->
        <GoodsInfo :goods="goods"></GoodsInfo>
          <!-- Sku -->
       <GoodsSku :goods="goods"></GoodsSku>
        </div>
      </div>
      <!-- 【商品详情】 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { reqFindGoods } from '@/api/goods'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import GoodsSale from './component/goods-sale'
import GoodsInfo from './component/goods-info'
import GoodsSku from './component/goods-sku'
export default {
  name: 'XtxGoodsPage',
  components: {
    GoodsSale,
    GoodsInfo,
    GoodsSku
  },
  setup () {
    // route 获取参数的
    // router 路由跳转的
    const route = useRoute()
    const goods = ref({})
    // 根据商品 ID 获取详情，从详情里面拿到面包屑数据并进行渲染
    const getGoods = async () => {
      const res = await reqFindGoods(route.params.id)
      goods.value = res.result
    }
    getGoods()
    return { goods }
  }
}
</script>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
